package org.spring.springboot.controller;

import org.spring.springboot.entity.Schedule;
import org.spring.springboot.mapper.ScheduleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {

    @Autowired
    private ScheduleMapper jobMapper;

    /**
     * 添加定时任务
     */
    @PostMapping("add")
    public boolean add(@RequestBody Schedule sysJob) {
        return jobMapper.insertOne(sysJob);
    }

    /**
     * 修改定时任务
     */
    @PostMapping("update")
    public boolean update(@RequestBody Schedule sysJob) {
        jobMapper.updateValid(sysJob.getJobId(),"N");
        return jobMapper.insertOne(sysJob);
    }

    /**
     * 删除任务
     */
    @PostMapping("del/{jobId}")
    public boolean del(@PathVariable("jobId") Integer jobId) {
        Schedule scheduleSetting = jobMapper.selectOne(jobId);
        jobMapper.updateValid(jobId,"N");
        return jobMapper.insertOne(scheduleSetting);
    }

}